package jdtoextension;

import java.lang.reflect.Field;

import com.juancavallotti.jdto.SinglePropertyValueMerger;

/**
 */
public class FromObjectPropertyMerger<T, S> implements SinglePropertyValueMerger<T, S> {

    @Override
    public T mergeObjects(final S value, final String extraParam) {
        Field field;
        T result = null;
        try {
            field = value.getClass().getDeclaredField(extraParam);
            field.setAccessible(true);
            result = (T) field.get(value);

        } catch (SecurityException e) {
            throw new UnsupportedOperationException(e);
        } catch (NoSuchFieldException e) {
            throw new UnsupportedOperationException(e);
        } catch (IllegalArgumentException e) {
            throw new UnsupportedOperationException(e);
        } catch (IllegalAccessException e) {
            throw new UnsupportedOperationException(e);
        }
        return result;
    }

}
